<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<#include "/common/resources.ftl"/>
<script type="text/javascript">
	function m_submit(){
		window.saveOrEditForm.submit();
	}
	
	function m_back(){
		window.location.href = 'manage';
	}
	
	<#if errorMsg?exists >alert('${errorMsg}');</#if>

	var	areaId = '${areaId}';
	var	treePath = '${treePath}';
	
	//城市查询
	var findcity = function(pid,index,currentId){
		var obj = $(".areaSelect").eq(index);
		$.ajax({
			url:'${ctx}/common/area/queryArea',
			data: pid != null ? {parentId: pid} : null,
			dataType: "json",
			type:"post",
			cache: false,
			async: false,
			error:function(data){
			},
			success:function(data){
			    obj.empty();
				var optionHtml = '<option value=""> -请选择- </option>';
				var isshow = false;
				$.each(data, function(index, value){
						isshow = true;
						if(value.id == currentId) {
							optionHtml +=  '<option value="' + value.id + '" selected="selected">' + value.name + '</option>';
						} else {
							optionHtml +=  '<option value="' + value.id + '" >' + value.name + '</option>';
						}
				});
				if(index==3 && data.length>0){
					$("#street").show();
				}else{
					$("#street").hide();
				}
				obj.html(optionHtml);	
			}
		});
	}
	$(function(){
		var $areaId = $("#areaId");
		$(".areaSelect").change(function(){
			var type = $(this).attr("areaType");
			var areaId = $(this).val();
			if(areaId){
				$areaId.val(areaId);
				switch(type){
					case "1":
						$(".areaSelect").eq(1).empty();
						$(".areaSelect").eq(2).empty();
						$(".areaSelect").eq(3).empty();
						findcity(areaId,1,"");
						break;
					case "2":
						$(".areaSelect").eq(2).empty();
						$(".areaSelect").eq(3).empty();
						findcity(areaId,2,"");
						break;
					case "3":
						findcity(areaId,3,"");
						break;
					case "4":
						break;
					
				}
			}
		});
	    
    	if(areaId && treePath){
			$areaId.val(areaId);
			var treePathArr = (treePath+areaId).split(",");
			for(var i=1 ; i<treePathArr.length; i++){
				findcity(treePathArr[i-1],i-1,treePathArr[i]);
			}
		}else{
			findcity("",0,"");
		}
	});
	<#if errorMsg?exists >alert('${errorMsg}');</#if>
</script>
</head>
<body>
  <form action="${ctx}/xf/businesscircles/save_edit" method="post" class="loan_list_form" name="saveOrEditForm">
  <input type="hidden" name="id" value="<#if model?exists >${model.id}</#if>" />
  <div class="fm_sty" style="margin: 20px 0px 0px;">
       	<div class="ipt_line">
			<span class="ipt_title">城区</span>
			<select class="sel_big areaSelect" id="province" areatype="1"><option >请选择省份</option></select>
			<select class="sel_big areaSelect" id="city" areatype="2"><option>请选择城市</option></select>
			<select class="sel_big areaSelect" id="area" areatype="3"><option>请选择区县</option></select>
			<select class="sel_big areaSelect" id="street" areatype="4"><option>请选择街道</option></select>
			<input type="hidden" name="areaId" id="areaId" value="<#if model?exists >${model.areaId}</#if>" class="ipt_226" />
		</div>
       	<div class="ipt_line">
			<span class="ipt_title">商圈名称</span>
			<input type="text" name="name" value="<#if model?exists >${model.name}</#if>" class="ipt_226" />
		</div>
      <div class="ipt_line_long">
            <button class="red_100" onclick="javascript:m_submit();return false;">保存</button>
            <button class="red_100" onclick="javascript:m_back();return false;" style="background-color:#74D86A">返回</button>
      </div>
	</div>
	</form>
</body>
</html>
